home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
BINDER.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
8KB
|
279 lines
/*
binder.hpp -- Loose Data Binder v 1.7:
container class.
(C) Copyright 1992 John W. Small
All rights reserved
PSW / Power SoftWare
P.O. Box 10072
McLean, Virginia 22102 8072 USA
(703) 759-3838
*/
#ifndef Binder_HPP
#define Binder_HPP
#include <limits.h> // UINT_MAX
#include <iostream.h>
#include <iomanip.h>
/* Binder pointer types */
typedef void * voiD;
#define voiD0 ((voiD)0)
typedef voiD * voiDV;
#define voiDV0 ((voiDV)0)
typedef int (* BDRcomP)(const voiD D1, const voiD D2);
#define BDRcomP0 (( BDRcomP)0)
typedef void (* BDRapplY)(voiD D, voiD M, voiD A);
typedef int (* BDRdetecT)(voiD D, voiD M);
typedef class Binder * BindeR;
#define BindeR0 ((BindeR)0)
typedef voiD (*BDRsloaD)(istream& is, voiD thiS);
typedef BindeR * initVFTs; //mk constructor unique
#define initVFTsOnly ((initVFTs)0)
/* Binder constants */
#define BDR_MAXNODES ((unsigned)(UINT_MAX/sizeof(voiD)))
#define BDR_LIMIT 20U
#define BDR_DELTA 10U
#define BDR_NOTFOUND BDR_MAXNODES
#define BDR_SORTED 0x01U
#define BDR_BIND_ONLY 0x00U
#define BDR_DASSIGN 0x02U
#define BDR_DNEW 0x04U
#define BDR_DDELETE 0x08U
#define BDR_DSTORE 0x10U
#define BDR_ALL_FLAGS 0xFFU
class Binder {
private:
unsigned lowLimit, lowThreshold, first;
voiDV linkS;
unsigned limit, delta, nodes;
unsigned maxNodes, curNode, flags;
BDRcomP comP;
static Binder& comPv;
static unsigned comPID(BDRcomP comP);
static BDRcomP comPLU(unsigned ID);
int initData(unsigned flags,
unsigned maxNodes,
unsigned limit,
unsigned delta);
protected:
Binder (initVFTs) {}
void destruct();
virtual voiD Dassign(voiD, const voiD)
{ return voiD0; }
virtual voiD Dnew(const voiD) { return voiD0; }
virtual void Ddelete(voiD D) { delete (voiD) D; }
virtual int Dattach(voiD) { return 1; }
virtual void Ddetach(voiD) { return; }
static void sberror(const char * msg);
virtual void berror(const char * msg);
virtual void Dstore(ostream&, voiD) {}
virtual voiD Dload(istream&) { return voiD0; }
virtual void store(ostream& os);
static BindeR load(istream& is, BindeR thiS);
int vload(const char * filename,
BDRsloaD sloaD, voiD thiS);
public:
static int streamDebug;
static char memberTermChar;
static void RegisterComP(BDRcomP comP);
static void ForgetComPs() { comPv.allDel(); }
/* Constructors and destructor */
Binder (unsigned flags = BDR_BIND_ONLY,
unsigned maxNodes = BDR_MAXNODES,
unsigned limit = BDR_LIMIT,
unsigned delta = BDR_DELTA)
{ (void) initData(flags,maxNodes,
limit,delta); }
Binder (voiDV argv, unsigned argc = 0,
unsigned flags = BDR_BIND_ONLY);
Binder (const char *filename)
{ (void) vload(filename,(BDRsloaD)Binder::
load,this); }
int save(const char *filename);
voiDV vector();
virtual ~Binder() { destruct(); }
/*
You must override this destructor in any
descendant that overrides Ddelete() or
Ddetach(), i.e.
virtual ~DerivedFromBinder()
{ Binder::destruct(); }
This is because base destructors are called
after vfts are reset to their default values
for the base level. This means that
Binder::~Binder() calls Binder::Ddetach()
and perhaps Binder::Ddelete() instead of
the intended DerivedFromBinder::Ddetach()
or DerivedFromBinder::Ddelete().
*/
/* Housekeeping Primitives */
unsigned Limit() { return limit; }
unsigned setLimit(unsigned newLimit);
unsigned pack() { return setLimit(nodes); }
unsigned Delta() { return delta; }
unsigned setDelta(unsigned newDelta = BDR_DELTA);
unsigned Nodes() { return nodes; }
unsigned MaxNodes() { return maxNodes; }
unsigned setMaxNodes(unsigned newMaxNodes
= BDR_MAXNODES);
unsigned vacancy() { return maxNodes - nodes; }
unsigned vacancyNonElastic()
{ return limit - nodes; }
unsigned Flags(unsigned flags = BDR_ALL_FLAGS)
{ return (this->flags & flags); }
unsigned setFlags(unsigned flags)
{ return (this->flags |= flags); }
unsigned resetFlags(unsigned flags)
{ return (this->flags &= ~flags); }
Binder& operator<<(Binder& (*manipulator)(Binder&))
{ return (manipulator?
(*manipulator)(*this)
: *this); }
/* Elastic Array Primitives */
voiD atIns(unsigned n, voiD D);
voiD atInsNew(unsigned n, const voiD D);
voiD atRmv(unsigned n);
void allRmv();
int atDel(unsigned n);
voiD atDelAsg(unsigned n, voiD D);
int allDel();
voiD atPut(unsigned n, voiD D);
voiD atPutNew(unsigned n, const voiD D);
voiD atPutAsg(unsigned n, const voiD D);
voiD atGet(unsigned n);
voiD operator[](unsigned n)
{ return atGet(n); }
voiD atGetAsg(unsigned n, voiD D);
voiD atXchg(unsigned n, voiD D);
unsigned index(const voiD D);
int forEach(BDRapplY B,
voiD M = voiD0, voiD A = voiD0);
/* Stack - Deque - Queue Primitives */
voiD push(voiD D) { return atIns(0,D); }
voiD pushNew(const voiD D)
{ return atInsNew(0,D); }
voiD pop() { return atRmv(0); }
Binder& operator>>(voiD& D)
{ D = atRmv(0); return *this; }
int popDel() { return atDel(0); }
voiD popDelAsg(voiD D)
{ return atDelAsg(0,D); }
voiD top() { return atGet(0); }
voiD topAsg(voiD D) { return atGetAsg(0,D); }
voiD insQ(voiD D) { return atIns(nodes,D); }
Binder& operator<<(voiD D)
{ atIns(nodes,D); return *this; }
voiD insQNew(const voiD D)
{ return atInsNew(nodes,D); }
voiD unQ() { return atRmv(nodes-1); }
int unQDel() { return atDel(nodes-1); }
voiD unQDelAsg(voiD D)
{ return atDelAsg(nodes-1,D); }
voiD rear() { return atGet(nodes-1); }
voiD rearAsg(voiD D)
{ return atGetAsg(nodes-1,D); }
/* List (single and double linked) Primitives */
unsigned CurNode();
int setCurNode(unsigned n = BDR_MAXNODES);
voiD ins(voiD D);
voiD insNew(const voiD D);
voiD rmv();
int del();
voiD delAsg(voiD D);
voiD put(voiD D) { return atPut(curNode,D); }
voiD putNew(const voiD D)
{ return atPutNew(curNode,D); }
voiD putAsg(const voiD D)
{ return atPutAsg(curNode,D); }
voiD get() { return atGet(curNode); }
voiD getAsg(voiD D)
{ return atGetAsg(curNode,D); }
voiD next();
voiD operator++() { return next(); }
voiD nextAsg(voiD D);
voiD prev();
voiD operator--() { return prev(); }
voiD prevAsg(voiD D);
voiD firstThat(BDRdetecT B, voiD M = voiD0);
voiD lastThat(BDRdetecT B, voiD M = voiD0);
/* Priority Q, Set, Bag, Dictionary, Sort Primitives */
unsigned Sorted() { return (flags & BDR_SORTED); }
void unSort() { flags &= ~BDR_SORTED; }
void setComP(BDRcomP comP = BDRcomP0)
{ this->comP = comP;
flags &= ~BDR_SORTED; }
BDRcomP ComP() { return comP; }
int sort(BDRcomP comP = BDRcomP0);
voiD insSort(voiD D);
voiD insSortNew(const voiD D);
voiD insUnique(voiD D);
voiD insUniqueNew(const voiD D);
voiD findFirst(const voiD K);
voiD findNext(const voiD K);
voiD findLast (const voiD K);
voiD findPrev(const voiD K);
unsigned findAll(const voiD K);
}; /* class Binder */
extern ostream& BDRendm(ostream& os);
extern istream& BDRnextm(istream& is);
#endif /* Binder_HPP */